import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions, Keys

option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
option.add_experimental_option('useAutomationExtension',False)
driver = webdriver.Chrome(options=option)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{'source':'Object.defineProperty(navigator,"webdriver",{get:()=>undefind})'})
driver.get("https://www.baidu.com/")

# 放大浏览器
driver.maximize_window()

# 找到百度网页上的登录按钮,并点击
driver.find_element_by_xpath("//*[@id='s-top-loginbtn']").click()
time.sleep(3)
# 定位到账号输入框
driver.find_element(By.NAME,"userName").send_keys("15207535664")
time.sleep(3)

# 使用 tap 键,将焦点定位到密码输入框
# name = driver.find_element(By.NAME,"password")
name = driver.find_element(By.XPATH,"//*[@id='TANGRAM__PSP_11__password']")
name.send_keys(Keys.TAB)
time.sleep(3)
# ..输入密码
driver.find_element(By.XPATH,"//*[@id='TANGRAM__PSP_11__password']").send_keys("@jiatenghui.")
time.sleep(3)
# 使用 enter 提交表单
driver.find_element_by_css_selector("#TANGRAM__PSP_11__submit").send_keys(Keys.ENTER)
time.sleep(3)
driver.quit()